<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>	
	<script language="javascript" src="<%=contextPath%>/js/func.js"type=""></script>
	<script type="text/javascript" src="<%=contextPath%>/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="<%=contextPath%>/js/jquery.form.js"></script>
	<script type="text/javascript" language="javascript">  
		
			function toGetNewData() {
				setTimeout("getNewData();",600000);	//600秒=600*10^3=600000毫秒 
			}
			
			function getNewData() {
				location.href = "plan!getGzapList.do?searchBean.con6=1&datafrom=1&showtype=0";
			
			}

		</script>  
	<script type="text/javascript">
	Ext.onReady(function(){
		var tb = new Ext.Toolbar({
		    renderTo: Ext.get('tbar'),
		    items: [
		        {
		            text: '查询',
		             icon:"<%=contextPath%>/" + "images/query.gif",
		             hidden:<%=session.getAttribute("btn_query_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		             handler:cmt
		        }, {
		            text: '起草',
		            icon:"<%=contextPath%>/" + "images/tishi.png",
		            hidden:<%=session.getAttribute("btn_add_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toDetail('0')
		            }
		        }, {
		            text: '提交',
		            icon:"<%=contextPath%>/" + "images/pass.gif",
		            hidden:<%=session.getAttribute("btn_commit_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toConfirm('1');
		            }
	        	},{
		            text: '合并',
		            icon:"<%=contextPath%>/" + "images/zuhe1.gif",
		            hidden:<%=session.getAttribute("btn_shenhe_display") != null ? false:true%>,
		            handler:function() {
		            	toPermit(0)
		            }
	        	},{
		            text: '审核通过',
		            icon:"<%=contextPath%>/" + "images/editlink.gif",
		             hidden:<%=session.getAttribute("btn_shenhe_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toConfirm('9');
		            }
		        },{
				            text: '驳回',
				            icon:"<%=contextPath%>/images/save.gif",
				            handler:function() {toConfirm('0'); },
				            hidden:<%=session.getAttribute("btn_rejcet_display")!= null|| "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>
				} ,{
		            text: '起草任务单',
		            icon:"<%=contextPath%>/" + "images/tishi.png",
		            hidden:<%=session.getAttribute("btn_new_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toNewRwd('0')
		            }
		        },
		         {
		            text: '查看任务单',
		            icon:"<%=contextPath%>/" + "images/tishi.png",
		            hidden:<%=session.getAttribute("btn_see_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toSeeRwd('0')
		            }
		        },
		        {
		            text: '删除',
		            icon:"<%=contextPath%>/" + "images/delete.gif",
		            hidden:<%=session.getAttribute("btn_delete_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:deleteIt
		        },'-',
				{
				     text: '清空',
				     icon:"<%=contextPath%>/images/clear.png",
				     handler:resetForm
				},'-', 
				{
				            text: '导出',
				            icon:"<%=contextPath%>/images/excel_export.gif",
				            handler:function() {

							var options  = {
										url:'planList!setPost.do',
							            type:'post',
           								success:function(data)
            							{

                							document.getElementById("ifrDownLoad").src = "<%=contextPath%>/planList!createSqlCvs.do"; 
                							return;
               
            							},
            							error:function(xhr)
            							{
                							alert("业务操作失败。");
            							}							            
							            
							        };
					        
							  $('#frmM').ajaxSubmit(options);
							        
							  return false; 
	
				            }
				}
				]
		});
	});
	</script>
  </head>
 <body onload="toGetNewData()">
  <div id ='tbar'></div>
  <br>
		<div id="Layer" style="position:absolute;display:block left:0px; top:35px; width:100%; height:94%; z-index:1000; overflow:auto;">
		<form id="frmM" class="ct" name="frmM" method="POST" action="<%=contextPath%>/queryUser.do">
			<input type="hidden" id="hiddenids" name="hiddenids" value="${hiddenids}"/>
			<input type="hidden" name="searchBean.displayFlag" value="${searchBean.displayFlag}"/>
			<input type="hidden" name="searchBean.con1" id="searchBean.con1" value="${searchBean.con1}" >
			<input type="hidden" name="searchBean.con6" id="searchBean.con6" value="${searchBean.con6}" >
			<input type="hidden" name="searchBean.con8" id="searchBean.con8" value="${searchBean.con8}" >
			<input type="hidden" name="searchBean.con9" id="searchBean.con9" value="${searchBean.con9}" >
			<input type="hidden" name="searchBean.con19" id="searchBean.con19" value="${searchBean.con19}" >
			<input type="hidden" name="conditionHtml" />
			<table width="100%" id="contab" >
				
				<tr>
					<th >计划开始时间：</th >
					<td  align="left">
					<input type="text" size="9" readonly="true" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'searchBean.con3\')}'})" name="searchBean.con2" id="searchBean.con2" value=${searchBean.con2 }>
					<img onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'searchBean.con3\')}', el:$dp.$('searchBean.con2')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					
					~
					<input type="text" size="9" readonly="true" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'searchBean.con2\')}'})"  name="searchBean.con3" id="searchBean.con3" value=${searchBean.con3 }>
					<img onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'searchBean.con2\')}', el:$dp.$('searchBean.con3')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>
				<!--  	<th >班组</th >
					<td  align="left">
						<input type="hidden" name="searchBean.con4" id="searchBean.con4" value="${searchBean.con4}" >
						<input type="text" readonly="true" name="searchBean.con5" size="50" id="searchBean.con5" value="${searchBean.con5}"/>
						<img style='cursor:pointer' src="<%=contextPath%>/images/editlink.gif" title="选择班组" 
							onClick="javascript:getBz('searchBean.con4','searchBean.con5','searchBean.con1')" />
					</td>-->
					<td colspan="1">
					
					<input type="radio" id="con5" name="searchBean.con5" value="01" ${searchBean.con5=="01"?"checked":""} onClick="cmt();"/>当日
				    <input type="radio" id="con6" name="searchBean.con5" value="02" ${searchBean.con5=="02"?"checked":""} onClick="cmt();"/>明日
				    <input type="radio" id="con7" name="searchBean.con5" value="03" ${searchBean.con5=="03"?"checked":""} onClick="cmt();"/>隔日
				  
			        </td>
			        <th>班组：</th>
					<td>
						<s:select list="bzList" emptyOption="true" onchange="javascript:cmt()" name="searchBean.con18" width="300" listKey="id" listValue="organName"/>
					</td>
					<th>
						变电站：
					</th>
					<td>
						<input type="text" readonly="true" name="searchBean.con7" size="30" id="searchBean.con7" value="${searchBean.con7}"/>
						<img style='cursor:pointer' src="<%=contextPath%>/images/editlink.gif" title="选择变电站" 
						onClick="javascript:getBdz('searchBean.con8','searchBean.con7','searchBean.con9')" />
					</td>
				</tr>
			</table>
		<hr>
		<table width="100%" id="listtab">
    		<tr>
    			<th width="5">
	           <!--input name="chkAll" type="checkbox" id="chkAll"
				onclick="javascript:checkAll(this.form, 'id');" value="checkbox" -->
				</th>
				<th class="ct" width="10">
					折叠
				</th>
				<th class="ct" width="10">序号</th>
				<th class="ct" >变电站</th>
				<th class="ct" >总负责人</th>
				<th class="ct" width="150" >停电范围</th>
				<th class="ct" width="250">工作项目</th>
				<!--  <th class="ct" >班组</th>-->
				<th class="ct">开始时间</th>
				<th class="ct" >结束时间</th>
				<th class="ct" >到位人员</th>
				<th class="ct" >验收人员</th>
				<th class="ct" >状态</th>
			</tr>
			<c:forEach items="${list}" var="Tab" varStatus="status">
					<tr ondblclick="javascript:toDetail('<c:out value="${Tab.id}"/>')"s>
						<td >
								<c:set value="${Tab.id}," var="varName" />
								<c:if test='${fn:contains(hiddenids, varName)}'>
									<input type="checkbox" name="id" value="${Tab.id}" checked onClick="getAllIds(this)"/>
								</c:if>
								<c:if test='${fn:contains(hiddenids, varName) == false}'>
									<input type="checkbox" name="id" value="${Tab.id}" onClick="getAllIds(this)"/>
								</c:if>
						</td>
						<td width="5">
					 		<img id="imgo${Tab.id}" onclick="openDetail('${Tab.id}')" src="<%=contextPath%>/images/plus1.gif" align="absmiddle">
					 		<img id="imgc${Tab.id}" style="display:none" onclick="openDetail('${Tab.id}')" src="<%=contextPath%>/images/minus1.gif" align="absmiddle">
						</td>
						<td width="5"> 
						<a href="#" onClick="javascript:toDetail('<c:out value="${Tab.id}"/>')" >${status.index+1}
						</a>
					 		</td>
					 		<td width="60">${Tab['stationname']}</td>
					 		<td width="60">${Tab['responsible']}</td>
					 		<td width="150" style="text-align: left">${Tab['powerrange']}</td>
						<td width="30%" style="text-align: left">${Tab['workcontent']}</td>
						<!--  <td>
							<a href="#" onClick="javascript:toDetail('<c:out value="${Tab.id}"/>')" >
								${Tab['teamnames']}
							</a>
						</td>-->
						<td width="120">
						${Tab.startdate}
							
						</td>
						<td width="120">
							${Tab.enddate}</td>
						
						<td>${Tab['dwryname']}</td>
						<td>${Tab['ysrname']}</td>
						<td>
						<c:choose>
							<c:when test="${Tab.status == '0'}">待提交</c:when>
							<c:when test="${Tab.status == '1'}">待审核</c:when>
							<c:when test="${Tab.status == '9'}">审核通过</c:when>
						</c:choose>
						</td>
					</tr>
					<tr height="0" id="tr${Tab.id}" style="display:none"><td></td><td colspan="14"><div id="nr${Tab.id}"></div></td></tr>
					<tr height="0" style="display:none"><td></td><td colspan="14"></td></tr>
				</c:forEach>

				<c:if test="${list == null || fn:length(list) == 0 }">
					<tr>
						<td colspan="12" style="text-align: center">
							无相关记录
						</td>
					</tr>
				</c:if>
		</table>
			<table width="100%" id="tablestyle2">
			<tr>
				<td>
					<hr />
				</td>
			</tr>
			<tr>
				<td>${pageDown}</td>
			</tr>
		</table>
	</form>
	<iframe id="ifrDownLoad" style="display:none" src=""></iframe>	
		</div>
  </body>
  <script>

		// 查询
		function cmt(){
		if(document.getElementById("con5").checked == false && document.getElementById("con6").checked == false&& document.getElementById("con7").checked == false){
			document.frmM.action = "<%=contextPath%>/planList!getList.do?page=1&c=c&searchBean.con5=";
			}else{
			document.frmM.action = "<%=contextPath%>/planList!getList.do?page=1&c=c";
			}
			document.frmM.submit();
		}
   
   		// 新建修改进入详细页面
		function toDetail(id){
			//location.href = "<%=contextPath%>/plan!initMonthPlanDetail.do?id=" + id;
			parent.addTab("月度工作计划", "<%=contextPath%>/plan!initMonthPlanDetail.do?id="+id,id);
    
		}
	
		// 批准, 审核
		function toConfirm(flag)
		{
		
			var msg = flag == '1' ? '提交':'审核通过';
			if(flag=='0'){msg='驳回';}
			if(!isChecked("id")) {
		 			alert("请选择要" + msg + "选中的记录");
		 		return false;
		 	}
		    if(confirm("确定要" + msg + "选中的记录吗？")) {
		        document.frmM.action = "<%=contextPath%>/plan!confirmMonthPlan.do?flag=" + flag;
				document.frmM.submit();
		    }
		}

		// 删除
		function deleteIt()
		{
			if(!isChecked("id")) {
		 		alert("请选择要删除的记录");
		 		return false;
		 	}
		    if(confirm("确定要删除选中的记录吗？")) {
		       	document.frmM.action = "<%=contextPath%>/plan!deleteMonthPlan.do?";
				document.frmM.submit();
		    }
		}
			
		// 点击checkbox 获得选中的id 给 hidden
		function getAllIds(obj) {
			
				var hiddenids = document.getElementById("hiddenids").value;
				
				var thisid = obj.value;
				var chkflag = obj.checked;
				
				if (chkflag) {
					if (hiddenids == "") {
						hiddenids = "," + thisid + ",";
					} else {
						hiddenids += thisid + ",";
					}
				} else {
					
					if (hiddenids.indexOf("," + thisid + ",") != -1) {
					
						hiddenids = hiddenids.replace(("," + thisid + ","), ",");
					}
				}
				
				if (hiddenids == ",") {
					hiddenids = "";
				}
				
				 document.getElementById("hiddenids").value = hiddenids;

		}
		
		// 合并
		function toPermit(id) {
		
			Ext.Ajax.request({
				method :'POST',
				url :'plan!initPermitCheck.do',
				params : {
					hiddenids :document.getElementById("hiddenids").value
				},
				success : function(response) {
					if (response.responseText != '1') {
						Ext.MessageBox.alert('提示', '	请选择同一个变电站的数据合并！');
					} else {
						if(document.getElementById("hiddenids").value == "") {
		 					alert("请选择要合并的记录");
		 					return false;
		 				}
		    			if(confirm("确定要合并选中的记录吗？")) {
							location.href = "<%=contextPath%>/plan!initPermit.do?id=" + id + "&hiddenids=" +  document.getElementById("hiddenids").value;
						}
					}
				},
				failure : function() {
					Ext.MessageBox.alert('提示', '删除失败！');
				}
			});
		}
		
		// 起草任务单
		function toNewRwd(id){
		
			if(!isChecked("id")) {
		 		alert("请选择一条记录");
		 		return false;
		 	}

		 	id1 = getCheckValue("id");//获取id值
		 	/**Ext.Ajax.request({
				method :'POST',
				url :'gzrwd!initPermitCheck.do',
				params : {
					hiddenids :document.getElementById("hiddenids").value
				},
				success : function(response) {//alert(response.responseText);
					if (response.responseText == '1') {
						Ext.MessageBox.alert('提示', '	当日工单已经存在,请选择查看任务单！');
						return false;
					}else{
					parent.addTab("工作计划-起草任务单", "<%=contextPath%>/gzrwd!initDetail.do?searchBean.con1=0&id=" + id + "&hiddenids=" +  document.getElementById("hiddenids").value, id1);
   
					}
				},
				failure : function() {
					Ext.MessageBox.alert('提示', '查找失败！');
				}
			});*/
	
			//location.href = "<%=contextPath%>/gzrwdCreatePlan!initMonthPlanDetail.do?id=" + id;
			//location.href = "<%=contextPath%>/gzrwd!initDetail.do?searchBean.con1=0&id=" + id + "&hiddenids=" +  document.getElementById("hiddenids").value;
				// 打开窗口
		parent.addTab("工作计划-任务单", "<%=contextPath%>/gzrwd!initDetail.do?searchBean.con1=0&id=" + id + "&hiddenids=" +  document.getElementById("hiddenids").value, id1);
   
				}
		
		// 打开详细任务
		function openDetail(recordid) {
		
			var str = "<table width='100%'  border='0'><tr><td width='6%'><b>参与班组</td><td width='6%'><b>负责人</td><td width='15%'><b>参与人员</td><td width='30%'><b>工作任务</td><td width='6%'><b>外用工</td><td width='10%'><b>车辆</td><td width='10%'><b>同车班组</td><td width='10%'><b>工单号</td><td width='10%'><b>日期</td></tr>";
			$.ajax({
				type: "post",
				url : "<%=contextPath%>/plan!getBzRw.do",
				dataType:'json',
			    async : false,
				data: 'id=' + recordid,
				success: function(json,state){

					if (json != null && json.length > 0) {
						for (var i=0; i<json.length;i++) {
							str += '<tr><td width="6%">' + json[i]["bzname"] + '&nbsp;</td><td width="6%">' + json[i]["fzrname"]+ '&nbsp;</td><td width="15%">' + json[i]["cyname"] + '&nbsp;</td><td width="30%">' + (json[i]["gzrw"]== null ? '' :  json[i]["gzrw"]) + '&nbsp;</td><td width="5%">' + json[i]["lsygrs"] + '&nbsp;</td><td width="10%">' + json[i]["cxch"] + '&nbsp;</td><td width="10%">' + json[i]["tcbz"] + '&nbsp;</td><td width="10%">' + json[i]["bh"] + '&nbsp;</td><td width="10%">' + json[i]["rq"] + '&nbsp;</td></tr>'
						}
					}

				},
				error:function(json) {
					alert("异步失败！");
				}
			});
					
			str += '</table>';

			var flag = "0";
		    if(document.getElementById('nr' + recordid).innerHTML != "" && document.getElementById('tr' + recordid).style.display!="") {
		         document.getElementById('tr' + recordid).style.display="";
		      	$('#imgc' + recordid).show();
		      	$('#imgo' + recordid).hide();
		         return;
		    } 
		      
		    if (document.getElementById('nr' + recordid).innerHTML == ""){
		      	$('#nr' + recordid).html(str);
		      	document.getElementById('tr' + recordid).style.display="";
		      	$('#imgc' + recordid).show();
		      	$('#imgo' + recordid).hide();
		      	flag = "1";
		    }
		      
		    if (flag == "0") {
		      	document.getElementById('tr' + recordid).style.display="none";
		      	
		         $('#imgc' + recordid).hide();
		         $('#imgo' + recordid).show();
		     }

		}
		            
		// 查看任务单
		function toSeeRwd(id){
		
			if(!isChecked("id")) {
		 		alert("请选择一条记录");
		 		return false;
		 	}

		 	id1 = getCheckValue("id");//获取id值
			//location.href = "<%=contextPath%>/gzrwdCreatePlan!initMonthPlanDetail.do?id=" + id;
			//location.href = "<%=contextPath%>/gzrwd!getGzrwdList.do?searchBean.con1=0&id=" + id1 + "&hiddenids=" +  document.getElementById("hiddenids").value;
			// 打开窗口
		//parent.addTab("工作计划-任务单", "<%=contextPath%>/gzrwd!getGzrwdList.do?searchBean.con1=0&id=" + id1 + "&hiddenids=" +  document.getElementById("hiddenids").value, id1);
   parent.addTab("工作计划-查看任务单", "<%=contextPath%>/gzrwdList!getList.do?searchBean.con1=0&planid=" + id1 + "&hiddenids=" +  document.getElementById("hiddenids").value, id1);
   
				}
	function reject(){
        state=0;
  		document.frmM.action = "<%=contextPath%>/plan!reject.do?flag="+state;
     	document.frmM.submit();
		    }
		
	</script>
</html>
